package com.ylbh.modules.newinfo.controller;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.newinfo.entity.ShoppingNewsClass;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ylbh.modules.newinfo.service.ShoppingNewsClassService;

import java.util.Arrays;


/**
 *
 * 新闻分类
 * @author czx
 * @date 2019-04-11 12:47:25
 */
@RestController
@RequestMapping("newsClass")
public class ShoppingNewsClassController {
    @Autowired
    private ShoppingNewsClassService shoppingNewsClassService;

    @ApiOperation("新闻分类列表")
    @RequestMapping("queryNewClassList")
    @RequiresPermissions("newsClass:queryNewClassList")
    public CommonResult<PageUtils> queryNewClassList(PageDTO pageDTO) {
        PageUtils list = shoppingNewsClassService.queryNewClassList(pageDTO);
        return Ref.ok(list);
    }

    @ApiOperation("新闻分类查看")
    @RequestMapping("getNewClassById/{id}")
    @RequiresPermissions("newsClass:getNewClassById")
    public CommonResult<ShoppingNewsClass> getNewClassById(@PathVariable(value = "id")String id) {
        ShoppingNewsClass newsClass = shoppingNewsClassService.getNewClassById(id);
        return Ref.ok(newsClass);
    }

    @SysLog("新闻分类修改")
    @ApiOperation("新闻分类修改")
    @RequestMapping("modifyNewClassById")
    @RequiresPermissions("newsClass:modifyNewClassById")
    public CommonResult<Void> modifyNewClassById(@RequestBody ShoppingNewsClass shoppingNewsClass) {
        shoppingNewsClassService.modifyNewClassById(shoppingNewsClass);
        return Ref.ok();
    }

    @SysLog("新闻分类新增")
    @ApiOperation("新闻分类新增")
    @RequestMapping("addNewClass")
    @RequiresPermissions("newsClass:addNewClass")
    public CommonResult<Void> addNewClass(@RequestBody ShoppingNewsClass shoppingNewsClass) {
        shoppingNewsClassService.addNewClass(shoppingNewsClass);
        return Ref.ok();
    }

    @SysLog("删除新闻分类")
    @ApiOperation("删除新闻分类")
    @RequestMapping("/removeNewClassByIds")
    @RequiresPermissions("newsClass:removeNewClassByIds")
    public CommonResult<Void> removeNewClassByIds(@RequestBody String[] newsIds){
        shoppingNewsClassService.removeNewClassByIds(Arrays.asList(newsIds));
        return Ref.ok();
    }

}
